﻿--[[
   @brief    web utility functions
   @author   sogoodchen;hqzheng
   @version  1.0
   @date     2016-01-08
--]]

web_utility = 
{

    init = function()
        local tpf_ui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");
        tpf_ui:RegisterJsEvent("m_get_client_info", "web_utility.handel_js_get_client_info");
        tpf_ui:RegisterJsEvent("tgp_monitor_report", "web_utility.tgp_monitor_report");
        tpf_ui:RegisterJsEvent("tgp_accurate_ad_report", "web_utility.tgp_accurate_ad_report");
    end;
    -- brief: lua call js public function
    -- param: func name json param
    -- return: null
    lua_call_js = function(func_name, json, custom_id)
        local nQBWebID = ui_utility.uilib():GetControlIDbyCustomID(custom_id);
        local pControl = ui_utility.uilib():GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        if pQBWeb == nil then
            -- base_utility.log("[utility]lua_call_js Web is nil "..func_name);
            web_utility.inner_log("lua_call_js Web is nil "..func_name);
            return ;
        end
        
        -- base_utility.log("[utility]lua_call_js "..func_name);
        web_utility.inner_log("lua_call_js "..func_name..
                ", " .. tostring(json));
        
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        pQBWeb:ExcecuteJS(const_func_name, const_json_param);
        web_utility.inner_log("lua_call_js success.");
        -- base_utility.log("[utility]lua_call_js success.");
    end;

    -- brief: lua call js public function(调用新的c++接口，直接根据和web约定的接口名调用Js)
    -- param: func name json param
    -- return: null
    lua_call_js_ex = function(func_name, json, custom_id)
        local tpf_ui = base_utility.get_component_adapter("ITpf_ui",
                    "ierd_tgp.tpf_ui.GetTPFUI();");
        if tpf_ui:TryRespondPluginJsCall(func_name, json) == true then
            return;
        end;
        local nQBWebID = ui_utility.uilib():GetControlIDbyCustomID(custom_id);
        local pControl = ui_utility.uilib():GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        if pQBWeb == nil then
            -- base_utility.log("[utility]lua_call_js_ex Web is nil "..func_name);
            web_utility.inner_log("lua_call_js_ex Web is nil "..func_name);
            return ;
        end
        -- base_utility.log("[utility]lua_call_js_ex "..func_name);
        web_utility.inner_log("lua_call_js_ex "..func_name ..
            ", " .. json);
        
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        pQBWeb:ExcecuteJSEx(const_func_name, const_json_param);
        web_utility.inner_log("lua_call_js_ex success.");
        -- base_utility.log("[utility]lua_call_js_ex success.");
    end;

    -- brief: lua call js public function
    -- param: func name json param
    -- return: null
    lua_call_js_by_id = function(func_name, json, web_id)
        local pControl = ui_utility.get_ctrl_ptr_by_id(web_id);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        if pQBWeb == nil then
            -- base_utility.log("[utility]lua_call_js_by_id Web is nil "..func_name);
            web_utility.inner_log("lua_call_js_by_id Web is nil "..func_name);
            return ;
        end
        
        -- base_utility.log("[utility]lua_call_js_by_id "..func_name);
        web_utility.inner_log("lua_call_js_by_id "..func_name ..
                ", " .. json);
        
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        pQBWeb:ExcecuteJS(const_func_name, const_json_param);
        web_utility.inner_log("lua_call_js_by_id success.");
        -- base_utility.log("[utility]lua_call_js_by_id success.");
    end;

    -- brief: lua call js public function(调用新的c++接口，直接根据和web约定的接口名调用Js)
    -- param: func name json param
    -- return: null
    lua_call_js_by_id_ex = function(func_name, json, web_id)
        local tpf_ui = base_utility.get_component_adapter("ITpf_ui",
                    "ierd_tgp.tpf_ui.GetTPFUI();");
        if tpf_ui:TryRespondPluginJsCall(func_name, json) == true then
            return;
        end;
        local pControl = ui_utility.get_ctrl_ptr_by_id(web_id);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBWebBrowser");
        if pQBWeb == nil then
            -- base_utility.log("[utility]lua_call_js_by_id Web is nil "..func_name);
            web_utility.inner_log("lua_call_js_by_id Web is nil "..func_name);
            return ;
        end
        
        -- base_utility.log("[utility]lua_call_js_by_id "..func_name);
        web_utility.inner_log("lua_call_js_by_id "..func_name..
                ", " .. json);
        
        local const_func_name, str_func_name = U8toCUIStr(func_name);
        local const_json_param, str_json_param = U8toCUIStr(json);
        pQBWeb:ExcecuteJSEx(const_func_name, const_json_param);
        web_utility.inner_log("lua_call_js_by_id success.");
        -- base_utility.log("[utility]lua_call_js_by_id success.");
    end;

    -- brief: 构造带登录态的网页url
    -- param: 原始网页URl, 
    -- param: uin
    -- return: login_status_url
    make_login_status_url = function(primitive_url, uin)
        if base_utility.CLIENT_TYPE.OVERSEA_VER == base_utility.get_client_version_type() or
            uin == 0 then
            return primitive_url;   -- 没有uin，认为是非qq登录，海外版也不需要ptlogin
        end
        local login_mgr =
            base_utility.get_component_adapter("ILogin_mgr",
                "ierd_tgp.login_mgr.GetLoginMgr();");
        --获取登录网页票据
        local info = ierd_tgp.login_mgr.WebStPod:new();
        login_mgr:GetWebSt(info);
        local url_prefix = LoadStr("PTLOGIN2_URL") .. "keyindex=18&clientuin=";
        local login_status_url = url_prefix .. uin.."&clientkey="..info.web_st.."&u1="..primitive_url;
        info:delete();
        return login_status_url;
    end;
    
    -- brief: 构造精准广告带登录态的网页url
    -- param: 原始网页URl, 
    -- param: uin
    -- return: login_status_url
    make_login_status_url_for_tcls_ad = function(primitive_url, uin)
        if base_utility.CLIENT_TYPE.OVERSEA_VER == base_utility.get_client_version_type() 
            or uin == 0 then
            return primitive_url;   -- 没有uin，认为是非qq登录，海外版也不需要ptlogin
        end
        local login_mgr =
            base_utility.get_component_adapter("ILogin_mgr",
                "ierd_tgp.login_mgr.GetLoginMgr();");
        --获取登录网页票据
        local info = ierd_tgp.login_mgr.WebStPod:new()
        login_mgr:GetWebSt(info);
        local url_prefix = LoadStr("PTLOGIN2_URL") .. "keyindex=18&clientuin=";
        local login_status_url = url_prefix ..uin.."&clientkey="..info.web_st.."&daid=8".."&u1="..primitive_url;
        info:delete();
        return login_status_url;
    end;

    make_ptlogin_url = function(web_relative_path,protocol)
        if protocol == nil then
            protocol = "https"
        end

        local dst_url = "";
        local url = protocol..LoadStr("PLAT_TGP_URL")..web_relative_path;
        dst_url = web_utility.make_login_status_url(url, login_model.main_uin);
        return dst_url;
    end;

    -- get_link_param : 获取link的参数
    -- cmd : json格式的命令字符串，见“trunk\client\docs\design_docs\TGP内部链接格式.txt”
    -- key: 参数中的键名
    -- return: 参数的键值
    get_link_param = function(cmd, key)
        if cmd == nil or cmd == "" then
            base_utility.log("[utility][get_link_param] param is empty");
            return;
        end

        if type(cmd) ~= 'string' then
            if type(cmd) == 'table' then
                cmd = base_utility.table_to_json(cmd);
            else
                base_utility.log("[utility][get_link_param] param type is error");
                return;
            end
        end

        -- '{' => 123; '}' => 125
        if((string.byte(cmd, 1) ~= 123) or (string.byte(cmd, -1) ~= 125)) then
            base_utility.log('[utility][get_link_param] old format cmd('..cmd..')');
            cmd = web_utility.convert_old_inner_link_foramt(cmd);
            base_utility.log('[utility][get_link_param] convert to new format cmd('..cmd..')');
        end

        local info = base_utility.json_to_table(cmd);

        if info == nil or type(info) ~= 'table' then
            base_utility.log('[utility][get_link_param] bad json cmd('..cmd..')');
            return;
        end

        if key == nil or key == "" then
            return info;
        end

        return info[key];
    end;

    -- brief: 解析cmd，并跳转到tgp内各页面
    -- param: cmd - json格式的命令字符串，见“trunk\client\docs\design_docs\TGP内部链接格式.txt”
    -- return: 无
    open_link = function(cmd)
        if login_model ~= nil and login_model.running_mode == login_model.OFFLINE_MODE then
            base_utility.log("[utility][open_link] open_link stop in offline mode");
            return;
        end;
        -- '{' => 123; '}' => 125
        if((string.byte(cmd, 1) ~= 123) or (string.byte(cmd, -1) ~= 125)) then
            base_utility.log('[utility] open_link, old format cmd('..cmd..')');
            cmd = web_utility.convert_old_inner_link_foramt(cmd);
            base_utility.log('[utility] open_link, convert to new format cmd('..cmd..')');
        end;

        local info = base_utility.json_to_table(cmd);
        local local_op_from = 0;

        -- 先判空
        if info == nil then
            base_utility.log('[utility] open_link failed, bad json cmd('..cmd..')');
            return;
        end;

        --判断是否为新的通信格式，并提取data。
        if info.data ~= nil and info.seq_num ~= nil and info.dest ~=nil then
            local_op_from = tonumber(info.src);
            info = info.data;
            cmd = base_utility.table_to_json(info);
        end

        if info.type == nil then
            base_utility.log('[utility] open_link failed, cmd has no type, cmd('..cmd..')');
            return;
        end;

        -- 打开直播间
        if info.type == "GAME_LIVE" then
            local param = { };
            param.module_id = GAME_ID.GAME_ID_GAME_LIVE;
            event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(param));
            return;
        end

        -- 处理open_web命令
        if info.type == "open_web" then
            local use_ptlogin = true;  -- 先默认设置为true（针对老的没有带use_ptlogin的请求）
            if info.use_ptlogin == "1" then
                use_ptlogin = true;
            elseif info.use_ptlogin == "0" then
                use_ptlogin = false;
            end
            local use_sys_browser = false;
            local use_new_browser = false;
            if info.browser == "sys" then
                use_sys_browser = true;
            elseif info.browser == "new" or info.browser == "os" then
                use_new_browser = true;
            elseif info.browser == "game_topic_detail" then
                event_center.send_event(browser_event.OPEN_GAME_TOPIC_DETAIL, cmd);
                return;
            elseif info.browser == "multi_web" then
                web_utility.open_multi_web(cmd, use_ptlogin);
                return;
            elseif info.browser == "ind_web_wnd" then
                event_center.send_event(browser_event.OPEN_IND_WEB_WND, cmd);
                return;
            end
            web_utility.open_new_browser(info.url, use_ptlogin,
            use_sys_browser, use_new_browser, info.title or "",
            info.width, info.height, info.have_scroll);
            return;
        end

        -- 打开LOL助手页LLU浮层
        if info.type == "open_llu" then
            if info.param ~= nil then
                web_utility.open_llu_param = info.param;
                local data = {};
                data.type = "landing";
                data.game_id = 26;
                web_utility.open_link(base_utility.table_to_json(data));
                local tpfui =base_utility.get_component_adapter("ITpf_ui",
                    "ierd_tgp.tpf_ui.GetTPFUI();");
                tpfui:AddInterval("web_utility.open_llu", 1000);
            end
            return;
        end

        if info.type == 'launch_webgame' then
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            local login_mgr =
                base_utility.get_component_adapter("ILogin_mgr",
                    "ierd_tgp.login_mgr.GetLoginMgr();");
            if game_lib == nil or login_mgr == nil then
                base_utility.log('[utility] open_link failed, query game_lib or login_mgr failed.');
                return;
            end
            local user_info = ierd_tgp.login_mgr.LoginedUserInfoPod:new();
            login_mgr:GetLoginedUserInfo(user_info);
            local uin = user_info.uin;
            user_info:delete();
            if uin == nil or uin == 0 then
                base_utility.log('[utility] open_link failed, webgame uin=0');
                return;
            end
            local game_id = tonumber(info.game_id);
            if game_id == nil then
                base_utility.log('[utility] open_link failed, webgame game_id('..info.game_id..') invalid.');
                return;
            end
            local server_id = tonumber(info.server_id) or 0;
            local op_from = tonumber(info.op_from) or 0;
            if local_op_from ~= 0 then
                op_from = local_op_from;
            end
            local ad_param = info.ad_param or "";
            local zone_type = info.zone_type or ierd_tgp.game_library.ZONE_TYPE_FORMAL;
            local ver = info.ver or "";
            game_lib:launch_game(game_id, server_id, uin, op_from,
                ad_param, zone_type, ver);
            return;
        end;
        if info.type == 'open_video' then
            event_center.send_event(browser_event.PLAY_VIDEO, base_utility.table_to_json(info));
            return;
        end;
        if info.type == 'open_topic_room' then
            comm_center.call_service("i_service_social_open_topic_room", info.param);
            return;
        end;
        if info.type == 'open_social' then
            comm_center.call_service("i_service_new_social_open_panel", info);
            return;
        end;

        -- 打开徽章相关窗口
        if info.type == "badge" then
            event_center.send_event(badge_event.OPEN_BADGE_WIN, cmd);
            return;
        end;

        if info.type == "open_game_update" then
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            local common_info = ierd_tgp.game_library.Common_info_export:new_local();
            game_lib:get_common_info(common_info);
            local rootUrl = common_info.tgp_web_url;

            if not web_utility.update_games[info.gameid] then
                local inf = {};
                local win_id = nil;
                inf.title = info.title;
                inf.gameid = info.gameid;
                inf.type = info.type;
                inf.width = 822;
                inf.height = 708;
                inf.url = rootUrl.."placard/update.html";
                inf.js_call_lua = {
                    jc_update_win_create = function(data)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            web_utility.lua_call_js_by_id("cj_update_win_create", 
                            base_utility.table_to_json(info.data), web_id);
                        end
                    end;
                };    
                inf.manuallyCloseCallback = function(win_id)
                    if info.type ~= nil and info.type == "open_game_update" then
                        ierd_tgp.tpf_ui.Require("tqos\\tqos.lua");
                        tqos_mgr.remember_btn_clicked("MAINWINDOW_GAME_UPDATE_CLOSE");
                        web_utility.update_games[info.gameid] = nil;
                    end;
                end;
                win_id = ui_utility.show_web(inf);
                web_utility.update_games[info.gameid] = win_id;
                return;
            else
                local pControl = ui_utility.uilib():GetControlPtr(web_utility.update_games[info.gameid]);
                local pPoptipsDlg = tolua.cast(pControl, "Tenio::ITDialog");
                pPoptipsDlg:Restore();
                pPoptipsDlg:BringToTop();
                return;
            end
        end;

        -- 打开我的资产
        if info.type == 'my_assets' then
            if not web_utility.my_assets_win then
                local inf = {};
                local win_id = nil;
                inf.title = LoadStr("COMMON_MY_ASSETS");
                inf.mtop = 0;
                inf.margin = 0;
                inf.width = 752;
                inf.height = 614;
                inf.ui_file = 'my_assets.tpf';
                inf.url = LoadStr("MY_ASSERT_URL");
                if info.sub_nav ~= nil and info.sub_nav ~= "" then 
                    inf.url = inf.url.."?sub_nav="..info.sub_nav;
                end;
                inf.show_until_web_complete = true;
                inf.delay_show_wnd = true;
                inf.js_call_lua = {
                    jc_get_my_gift_list = function(param)
                        base_utility.log('[utility] get_my_gift_list start.');
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.assets_win_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(extendboard_event.ON_JS_CALLBACK_GC, json);
                        end
                    end;

                    jc_get_user_info = function(param)
                        base_utility.log('[utility] get_user_info start.');
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.assets_win_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(extendboard_event.ON_JS_CALLBACK_GC, json);
                        end
                    end;

                    jc_get_game_states = function(param)
                        base_utility.log('[utility] get_game_states start.');
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(win_id, "web_con");
                            param.wnd_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(game_library_event.GET_GAME_STATES, json);
                        end
                    end;

                    jc_send_user_address_info = function(param)
                        base_utility.log('[utility] send_user_address_info start.');
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.assets_win_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(extendboard_event.ON_JS_CALLBACK_GC, json);
                        end
                    end;

                    jc_close = function()
                        base_utility.log('[utility] my_assets close start.');
                        if web_utility.my_assets_win > 0 then
                            local pControl = 
                                ui_utility.uilib():GetControlPtr(web_utility.my_assets_win);
                            local pPoptipsDlg = tolua.cast(pControl, "Tenio::ITDialog");

                            if pPoptipsDlg ~= nil then
                                pPoptipsDlg:Show(FALSE);
                            end;

                            layout_mgr.delay_remove_ctrl(web_utility.my_assets_win);
                            web_utility.my_assets_win = nil;
                            base_utility.log('[utility] my_assets close end.');
                        end
                    end;

                };
                inf.manuallyCloseCallback = function(win_id)
                    if web_utility.my_assets_win ~= nil then
                        web_utility.my_assets_win = nil;
                    end;
                end;
                win_id = ui_utility.show_web(inf);
                web_utility.my_assets_win = win_id;
                return;
            else
                local pControl = ui_utility.uilib():GetControlPtr(web_utility.my_assets_win);
                local pPoptipsDlg = tolua.cast(pControl, "Tenio::ITDialog");
                pPoptipsDlg:Restore();
                pPoptipsDlg:BringToTop();
                return;
            end
        end;

        -- 打开任务中心
        if info.type == 'task_center' then
            if not web_utility.task_center_win then
                local inf = {};
                local win_id = nil;
                inf.title = LoadStr("COMMON_TASK_CENTER");
                inf.width = 792;
                inf.mtop  = 39;
                inf.margin = 0;
                inf.height = 720;
                inf.ui_file = 'task_center.tpf';
                inf.url = LoadStr("POPBOX_TASKV2_URL");
                inf.is_multi_win = false;
                inf.js_call_lua = {
                    jc_task_list = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_TASK_LIST, json);
                        end
                    end;
    
                    jc_holly_wood_chk_flag = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_HOLLY_WOOD_CHK_FLAG, json);
                        end
                    end;
    
                    jc_blue_diamond_chk_flag = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_BLUE_DIAMOND_CHK_FLAG, json);
                        end
                    end;
    
                    jc_qm_software_chk_flag = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_QM_SOFTWARE_CHK_FLAG, json);
                        end
                    end;

                    jc_mobile_tgp_chk_flag = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_MOBILE_TGP_CHK_FLAG, json);
                        end
                    end;

                    jc_holly_wood_reward_list = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_HOLLY_WOOD_REWARD_LSIT, json);
                        end
                    end;
    
                    jc_blue_diamond_coupon = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_BLUE_DIAMOND_COUPON, json);
                        end
                    end;
    
                    jc_qm_software_reward = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_QM_SOFTWARE_REWARD, json);
                        end
                    end;

                    jc_mobile_tgp_reward = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_MOBILE_TGP_REWARD, json);
                        end
                    end;

                    jc_open_qm_url = function(param)
                        local url = LoadStr("GUANJIA_URL");
                        web_utility.open_browser(url, false, true);
                    end;
   
    
                    jc_activity_ext = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_ACTIVITY_EXT, json);
                        end
                    end;
    
    
                    jc_do_draw_act = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(extendboard_event.ON_JS_CALLBACK_GC, json);
                        end
                    end;
    
                    jc_draw_act_detail = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(extendboard_event.ON_JS_CALLBACK_GC, json);
                        end
                    end;

                    jc_set_start_list = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_SET_START_LIST, json);
                        end
                    end;

                    jc_get_start_list = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_GET_START_LIST, json);
                        end
                    end;

                    jc_sign_in_info = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_SIGN_IN_INFO, json);
                        end
                    end;

                    jc_sign_in = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JC_SIGN_IN, json);
                        end
                    end;

                    jc_check_is_in_visible_game_list = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(extendboard_event.CHECK_IS_IN_VISIBLE_GAME_LIST, json);
                        end
                    end;

                    jc_open_game_detail = function(param)
                        if win_id ~= nil and win_id > 0 then
                            if param ~= nil then
                                local json = base_utility.table_to_json(param);
                                web_utility.open_link_convert(json);
                            end
                        end
                    end;
            
                    jc_get_install_state = function(param)
                        if win_id ~= nil and win_id > 0 then
                            local web_id = ui_utility.get_ctrl_id_by_path(
                            win_id, "web_con");
                            param.web_id = web_id;
                            local json = base_utility.table_to_json(param);
                            event_center.send_event(personal_center_event.JS_GET_INSTALL_STATE, json);
                        end
                    end;
                };
                inf.manuallyCloseCallback = function(win_id)
                    if win_id == web_utility.task_center_win then
                        web_utility.task_center_win = nil;
                    end
                end;
                win_id = ui_utility.show_web(inf);
                web_utility.task_center_win = win_id;
                return;
            else
                local pControl = ui_utility.uilib():GetControlPtr(web_utility.task_center_win);
                local pPoptipsDlg = tolua.cast(pControl, "Tenio::ITDialog");
                pPoptipsDlg:Restore();
                pPoptipsDlg:BringToTop();
                return;
            end
        end;

        -- 获取用户的等级
        if info.type == 'get_current_level' then 
            event_center.send_event(game_library_event.GET_USER_LEVEL, base_utility.table_to_json(info));
            return;
        end;

        -- 激活事件
        if info.type == 'game_activate_result' then
            event_center.send_event(game_library_event.GAME_ACTIVATE_RESULT, base_utility.table_to_json(info));
            return;
        end;

        -- 启动游戏
        if info.type == 'launch_game' then
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            local login_mgr =
                base_utility.get_component_adapter("ILogin_mgr",
                    "ierd_tgp.login_mgr.GetLoginMgr();");
            if game_lib == nil or login_mgr == nil then
                base_utility.log('[utility] open_link failed, query game_lib or login_mgr failed.');
                return;
            end;
            local user_info = ierd_tgp.login_mgr.LoginedUserInfoPod:new();
            login_mgr:GetLoginedUserInfo(user_info);
            local uin = user_info.uin;
            user_info:delete();
            if uin == nil then
                base_utility.log('[utility] open_link failed, webgame uin=nil');
                return;
            end;
            local game_id = tonumber(info.game_id);
            if game_id == nil then
                base_utility.log('[utility] open_link failed, webgame game_id('..info.game_id..') invalid.');
                return;
            end;
            local server_id = tonumber(info.server_id) or 0;
            local op_from = tonumber(info.op_from) or 0;
            if local_op_from ~= 0 then
                op_from = local_op_from;
            end
            local ad_param = info.ad_param or "";
            local zone_type = info.zone_type or ierd_tgp.game_library.ZONE_TYPE_FORMAL;
            local ver = info.ver or "";

            game_lib:launch_game(game_id, server_id, uin, op_from, ad_param, zone_type, ver);
            return;
        end;

        if info.type == "update_game" then
            local action_info_ = {
                game_id_ = info.game_id,
                zone_id_ = 0,
                version_ = 0,
                uin_ = login_model.main_uin,
                launch_op_from = 0,
            };
            local param = {
                action = GameActions.kUpdateGame,
                action_info = base_utility.table_to_json(action_info_),
            };
            comm_center.send_broadcast("i_broadcast_excute_action", param);
            return;
        end;

        if info.type == "download_game" then
            local action_info_ = {
                game_id_ = info.game_id,
                zone_id_ = 0,
                version_ = 0,
                uin_ = login_model.main_uin,
                launch_op_from = 0,
            };
            local param = {
                action = GameActions.kDownloadGame,
                action_info = base_utility.table_to_json(action_info_),
            };
            comm_center.send_broadcast("i_broadcast_excute_action", param);
            return;
        end;

        if info.type == "open_activate_web" then
            local  data = {};
            local gl_adapter =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            local gl_common_info = ierd_tgp.game_library.Common_info_export:new();
            gl_adapter:get_common_info(gl_common_info);
            local activate_url = gl_common_info.tgp_web_url .. "mgamelibrary/game_activation.html?game_id=" .. info.game_id;
            local width = 484;
            local height = 210;
            local have_scroll = 0;
            if info.width ~= nil then
                width = info.width;
            end;
            if info.height ~= nil then
                height = info.height;
            end;
            web_utility.open_browser(activate_url, true, false, width, height, have_scroll);
            gl_common_info:delete() 
            return;
        end;

        if info.type == "get_game_install_state" then
            event_center.send_event(game_library_event.REQUEST_GAME_INSTALL, base_utility.table_to_json(info));
            return;
        end;
   
        -- 除了特殊的界面，打开内部链接时先把主窗口显示出来
        if info.type ~= 'tools' and info.type ~= 'gheadline' and info.type ~= 'event' then
            if wegame_mainframe_view.show(false) then
                event_center.send_event(mainframe_event.MAINFRAME_WND_SHOWN, "");
            end;
        end;
        
        -- 需要强制拉起大界面的得放在这里或者后面写
        if info.type == "landing" then
            local jump_params = {};
            jump_params.module_id = info.game_id;
            jump_params.module_url = info.url;
            event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(jump_params));
            
            -- 给助手页面传递数据
            if info.url ~= nil and info.url ~= "" then
                if tonumber(info.game_id) == GAME_ID.GAME_ID_LOL or
                    tonumber(info.game_id) == GAME_ID.GAME_ID_CF then
                    local game_lib =
                        base_utility.get_component_adapter("IGame_library",
                            "ierd_tgp.game_library.Get_game_library_adapter();");
                    if game_lib ~= nil then
                        game_lib:OpenTGPWindows(cmd);
                    end;
                end
            end;
            return;
        end;
        
--        -- 除了特殊的界面，打开内部链接时先把主窗口显示出来
--        if info.type ~= 'tools' and info.type ~= 'gheadline' and info.type ~= 'event' then
--            if wegame_mainframe_view.show(false) then
--                event_center.send_event(mainframe_event.MAINFRAME_WND_SHOWN, "");
--            end;
--        end;

        if info.type == "jump_url" then
            if info.url ~= nil then
                local params = {};
                params.module_id = info.id or GAME_ID.GAME_ID_SHOP;
                params.module_url = info.url;
                event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(params));
            end;
            return;
        end;
        
        if info.type == "add_banner" then
            local gl_adapter = base_utility.get_component_adapter("IGame_library",
                                "ierd_tgp.game_library.Get_game_library_adapter();");
            if gl_adapter ~= nil then
                gl_adapter:add_or_remove_game(tonumber(info.game_id), true);
            end
        end;

        if info.type == "profile" then
            local params = {};
            local page_info = web_utility.profile_sub_tab_info["HOME"];
            local vip_data = {};

            if info.sub_page ~= nil and web_utility.profile_sub_tab_info[info.sub_page] ~= nil then
                page_info = web_utility.profile_sub_tab_info[info.sub_page];
            end;
            
            
            local url_param = "";
            local has_param = false;

            local first_param = "?";
            if string.find(page_info.url, "?") ~= nil then
                first_param = "&";
            end;

            if info.tgp_id ~= nil then
                has_param = true;
                url_param = "tgpid=" .. tostring(info.tgp_id);
            else
                if nil ~= wegame_mainframe_model and 0 ~= wegame_mainframe_model.self_tgp_id then
                    has_param = true;
                    url_param = "tgpid="..tostring(wegame_mainframe_model.self_tgp_id);
                end;
            end;

            if info.custom_param ~= nil then
                has_param = true;
                if url_param == "" then
                    url_param = tostring(info.custom_param);
                else
                    url_param = url_param.."&"..tostring(info.custom_param);
                end;
            end

            params.module_id = GAME_ID.GAEM_ID_HOME_PAGE;
            params.module_url = page_info.url;
            if has_param then
                params.module_url = params.module_url..first_param..url_param;
            end
            event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(params));
        end;

        -- 希望后面加的这种直接传info，不要再让接收方再转换一次table了
        event_center.send_event(open_link_event.OPEN_LINK, cmd);
    end;

    -- open_link_convert : 支持界面关闭/最小化时跳转到指定页面
    -- link_info : 同web_utility.open_link参数
    open_link_convert = function(link_data)
        if login_model ~= nil and login_model.running_mode == login_model.OFFLINE_MODE then
            base_utility.log("[utility][open_link_convert] open_link stop in offline mode");
            return;
        end;
        if link_data == nil or link_data == "" then
            base_utility.log("[open_link_convert] param is empty");
            return;
        end;
        local link_info = "";
        if type(link_data) == 'table' then
            link_info = base_utility.table_to_json(link_data);
        elseif type(link_data) == 'string' then
            link_info = link_data;
        else
            base_utility.log("[open_link_convert] param type is error");
            return;
        end
        if link_info == "" then
            base_utility.log("[open_link_convert] link_info is empty");
            return;
        end;
        if wegame_mainframe_view.is_closed == false then -- 界面可见
            base_utility.log("[web_utility][open_link_convert] mainframe is open status");
            web_utility.open_link(link_info);
            web_utility.broadcast_open_link_finish(link_info);
        else -- 界面关闭
            base_utility.log("[web_utility][open_link_convert] mainframe is closed status");
            if wegame_mainframe_view.show(false) then -- 拉起界面
                event_center.send_event(mainframe_event.MAINFRAME_WND_SHOWN, "");
                web_utility.open_link_convert_info = link_info;
            end
        end
    end;

    -- open_link_convert_confirm_launch : 
    -- 功能同web_utility.open_link_convert 若是拉起游戏，增加二次判断
    -- link_info : 同web_utility.open_link参数
    open_link_convert_confirm_launch = function(link_data)
        local link_type = web_utility.get_link_param(link_data, "type");
        if link_type == nil then
            return;
        end
        if link_type ~= "launch_webgame" and link_type ~= "launch_game" then      
            -- 正常逻辑打开链接
            web_utility.open_link_convert(link_data);
        else
            -- 添加二次确认
            local param = {
                position = "center",
                title = "",
                width = 460,
                height = 230,
                titleIcon = "",
                icon = "",
                tipsIcon = poptips_icons.kInfo,
                descTitle = "",
                desc = "",
                modal = false,
                is_multi_win = true,
                okBtn = {
                    visible = true;
                    text = "",
                    handle = function()
                        web_utility.open_link_convert(link_data);
                        poptips_control.close_tips();
                    end
                },
                cancelBtn = {
                    visible = true,
                    text = "",
                    handle = function()
                    end
                }
            };
            -- 标题和内容国际化
            param.title = LoadStr(ID_TIPS_LAUNCH_GAME_TITLE);
            param.desc = LoadStr(ID_TIPS_LAUNCH_GAME_TEXT);
            param.okBtn.text = LoadStr(ID_TIPS_OK);
            param.cancelBtn.text = LoadStr(ID_TIPS_CANCEL);
            -- 显示二次确认窗口
            ui_utility.show_tips(param);
        end
    end;

    handle_open_link_convert = function(data)
        if web_utility.open_link_convert_info ~= nil then
            -- web页面初始化，最后一个注册完成
            local cur_open_link = web_utility.open_link_convert_info;
            web_utility.open_link_convert_info = nil;
            web_utility.open_link(cur_open_link);
            web_utility.broadcast_open_link_finish(cur_open_link);
        end
    end;

    broadcast_open_link_finish = function(link_info)
        if link_info == nil then
            return;
        end;
        local table_data = nil;
        if type(link_info) ~= "table" then
            table_data = base_utility.json_to_table(link_info);
        else
            table_data = link_info;
        end

        if table_data == nil then
            return;
        end
        if table_data.extra_info ~= nil and table_data.extra_info.need_broadcast ~= nil 
            and table_data.extra_info.need_broadcast == true then
            comm_center.send_broadcast("i_broadcast_open_link_finish", table_data);
        end;
    end;

    open_game_detail_page =  function(data)
        if data == nil or data.game_id == nil then
            base_utility.log("[web_utility]open_game_detail_page: param data is nil");
            return;
        end
        local param = {}
        param.type ="mmo_game"
        param.sub_page ="GAME_DETAIL"
        param.game_id = data.game_id
        if data.page_tab ~= nil then
            param.page_tab =  data.page_tab
        end
        if data.extra_info ~= nil then
            param.extra_info =  data.extra_info;
        end
        web_utility.open_link_convert(base_utility.table_to_json(param));
    end;

    open_web_page_by_url =  function(data)
        if data == nil or data.url == nil then
            base_utility.log("[web_utility]open_web_page_by_url: param data is nil");
            return;
        end
        local param = {}
        param.type ="jump_url"
        if data.id ~= nil then
            param.id = data.id  -- module_id
        else
            param.id = GAME_ID.GAEM_ID_HOME_PAGE
        end
         param.url = data.url
        web_utility.open_link_convert(base_utility.table_to_json(param));
    end;

    open_multi_web = function(json, use_pt)
        local params = base_utility.json_to_table(json);
        base_utility.log("[web_utility]open_multi_web,json："..json);
        if params.url ~= nil then
            base_utility.log("[web_utility]open_multi_web,url:"..params.url);
            local i, j = string.find(params.url, "qq.com");
            local url;
            if i ~= nil and j ~= nil and use_pt then 
                params.url = web_utility.make_login_status_url(params.url, login_model.main_uin);
            end;
            event_center.send_event(tab_browser_event.OPEN_NEW_TAB_SINGLETON, base_utility.table_to_json(params));
        end;
    end;

    -- brief: 打开页面
    -- 新的打开浏览器的做法，希望以后慢慢切换到新的
    -- url：页面地址
    -- use_ptlogin：是否带登录态
    -- use_sys_browser：是否使用系统默认浏览器
    -- use_new_browser：是否使用新的浏览器
    -- width：宽，可以不填，只在use_sys_browser为false时生效
    -- height：高，可以不填，只在use_sys_browser为false时生效
    open_new_browser = function(url, use_ptlogin, use_sys_browser,
        use_new_browser, title, width, height, have_scroll)
        if use_ptlogin then
            url = web_utility.make_login_status_url(url, login_model.main_uin);
        end
        if use_sys_browser then
            ierd_tgp.tpf_ui.open_default_browser(url);
            return;
        end

        local param = {};
        param.title = "";
        param.url = url;
        param.width = width;
        param.height = height;
        param.have_scroll = have_scroll;
        
        if use_new_browser then
            if title and title ~= "" then
                param.title = title;
            end
            event_center.send_event(browser_event.OPEN_TGP_NEW_BROWSER, base_utility.table_to_json(param));
            return;
        end

        event_center.send_event(browser_event.OPEN_TGP_BROWSER, base_utility.table_to_json(param));
    end;

    -- brief: 打开页面
    -- TODO 老的打开浏览器的做法，希望以后慢慢切换到新的
    -- url：页面地址
    -- use_ptlogin：是否带登录态
    -- use_sys_browser：是否使用系统默认浏览器
    -- width：宽，可以不填，只在use_sys_browser为false时生效
    -- height：高，可以不填，只在use_sys_browser为false时生效
    open_browser = function(url, use_ptlogin, use_sys_browser, width, height, have_scroll)
        if use_ptlogin then
            url = web_utility.make_login_status_url(url, login_model.main_uin);
        end
        if use_sys_browser then
            ierd_tgp.tpf_ui.open_default_browser(url);
            return;
        end
        local param = {};
        param.url = url;
        param.width = width;
        param.height = height;
        param.have_scroll = have_scroll;
        event_center.send_event(browser_event.OPEN_TGP_BROWSER, base_utility.table_to_json(param));
    end;

    --运营配置的url格式如：www.baidu.com?id=50110001, 不能超过20亿
    --"id="后面为urlid, urlid分为两部分，前3位是位置编号(501)，后面部分为资源编号(10001)
    get_url_id = function(url)
        local pos_id = 0;
        local res_id = 0;
        local id = web_utility.get_param_from_url(url, "id");
        if id ~= nil and string.len(id) > 3 then
            pos_id = tonumber(string.sub(id, 1, 3));
            res_id = tonumber(string.sub(id, 3, string.len(id)));
        end
        return pos_id, res_id, id;
    end;

    -- brief: get param from url.etc:http://www.qq.com?parama=123&paramb=tgp
    -- param: url and param name
    -- return: param str, return nil if param not exist
    get_param_from_url = function(url, name)
        local mark = name .. "=";
        local startp = string.find(url, mark);
        if startp == nil then
            return nil;
        end
        startp = startp + string.len(mark);
        local endp = string.find(url, '&', startp);
        if endp == nil then
            return string.sub(url, startp);
        end
        return string.sub(url, startp, endp - 1);
    end;

    ----------------------------------------
    -- 此行以下的函数和变量不对外提供服务 --
    ----------------------------------------
    convert_old_inner_link_foramt = function(old_format_str)
        -- 首页
        if (old_format_str == 'homepage') then
            return '{"type":"homepage"}';
        end;

        -- 游戏库
        local i, j = string.find(old_format_str, "game:");
        if (i == 1) then
            local game_id = string.sub(old_format_str, j+1);
            if game_id == '0' then
                return '{"type":"mmo_game", "sub_page":"ALL_GAME","game_id":"0"}';
            end;
            return '{"type":"mmo_game", "sub_page":"GAME_DETAIL","game_id":"'..game_id..'"}';
        end;

        -- 礼包兑换
        i, j = string.find(old_format_str, "gift:");
        if (i == 1) then
            local game_id = string.sub(old_format_str, j+1);
            if game_id == '' or game_id == '90000' then
                return '{"type":"gift", "sub_page":"ALL_GAME","game_id":"0"}';
            end;
            if game_id == '90001' then
                return '{"type":"gift", "sub_page":"MY_GIFT","game_id":"0"}';
            end;
            if game_id == '90002' then
                return '{"type":"gift", "sub_page":"LUCK_DRAW","game_id":"0"}';
            end;
            return '{"type":"gift", "sub_page":"GAME_GIFT","game_id":"'..game_id..'"}';
        end;

        -- 工具箱
        i, j = string.find(old_format_str, "tools");
        if (i == 1) then
            local sub_page = string.sub(old_format_str, j+2);
            if sub_page == '' then
                return '{"type":"tools", "sub_page":"HOME","game_id":"0"}';
            end;
            if sub_page == 'SPEEDUP_CNT_PAGE' then
                return '{"type":"tools", "sub_page":"NET_ACCE","game_id":"0"}';
            end;
            if sub_page == 'PRELOAD_PAGE' then
                return '{"type":"tools", "sub_page":"START_ACCE","game_id":"0"}';
            end;
            if sub_page == 'SECURITY_CNT_PAGE' then
                return '{"type":"tools", "sub_page":"SECURITY_CENTER","game_id":"0"}';
            end;
            if sub_page == 'GAME_MGR_PAGE' then
                return '{"type":"tools", "sub_page":"GAME_MGR","game_id":"0"}';
            end;
            if sub_page == 'LOL_REPAIR_PAGE' then
                return '{"type":"tools", "sub_page":"LOL_REPAIR","game_id":"0"}';
            end;
            i, j = string.find(old_format_str, "tools:GAME_AUTO_UPDATE_PAGE game_id:");
            if i == 1 then
                local game_id = string.sub(old_format_str, j+1);
                return '{"type":"tools", "sub_page":"AUTO_UPDATE","game_id":"'..game_id..'"}';
            end;
            return '{"type":"tools", "sub_page":"HOME","game_id":"0"}';
        end;

        -- 我的特权
        if (old_format_str == 'privilege') then
            return '{"type":"personal_center", "sub_page":"MY_PRIVILEGE"}';
        end;

        -- 游戏启动
        i, j = string.find(old_format_str, "landing:");
        if (i == 1) then
            local game_id = '0';
            local game_id_i = string.find(old_format_str, 'landing:');
            if game_id_i ~= nil then
                game_id = string.sub(old_format_str, game_id_i + 8);
                game_id_i = string.find(game_id, ' ');
                if game_id_i ~= nil then
                    game_id = string.sub(game_id, 1, game_id_i - 1);
                end;
            end;
            local url = '';
            local url_i = string.find(old_format_str, ' url:');
            if url_i ~= nil then
                url = string.sub(old_format_str, url_i + 5);
                url_i = string.find(url, ' ');
                if url_i ~= nil then
                    url = string.sub(url, 1, url_i - 1);
                end;
            end;
            local video = '';
            local video_i = string.find(old_format_str, ' video:');
            if video_i ~= nil then
                video = string.sub(old_format_str, video_i + 7);
                video_i = string.find(video, ' ');
                if video_i ~= nil then
                    video = string.sub(video, 1, video_i-1);
                end;
            end;
            return '{"type":"landing","game_id":"'..game_id..'","url":"'..url..'", "video":"'..video..'"}';
        end;

        -- TGP设置
        i, j = string.find(old_format_str, "setting:");
        if (i == 1) then
            local sub_type = string.sub(old_format_str, j+1);
            if sub_type == '' or sub_type == '0' then
                return '{"type":"setting", "sub_page":"ROUTINE_SETTING"}';
            end;
            if sub_type == '1' then
                return '{"type":"setting", "sub_page":"GAME_DL_SETTING"}';
            end;
            return '{"type":"setting", "sub_page":"ROUTINE_SETTING"}';
        end;

        -- 个人中心
        if (old_format_str == 'personal_center') then
            return '{"type":"personal_center", "sub_page":"DAILY_TASK"}';
        end;

        -- 打开网页
        i, j = string.find(old_format_str, "web:");
        if (i == 1) then
            local url = string.sub(old_format_str, j+1);
            return '{"type":"open_web", "browser":"os", "use_ptlogin":"1", "url":"'..url..'"}';
        end;
        i, j = string.find(old_format_str, "inner_web:");
        if (i == 1) then
            local url = string.sub(old_format_str, j+1);
            return '{"type":"open_web", "browser":"tgp", "use_ptlogin":"1", "url":"'..url..'"}';
        end;

        -- 启动网页游戏
        i, j = string.find(old_format_str, "webgame:");
        if (i == 1) then
            local game_id = string.sub(old_format_str, j+1);
            return '{"type":"launch_webgame", "game_id":"'..game_id..'", "server_id":"0", "op_from":"0", "ad_param":"", "zone_type":"", "ver":""}';
        end;

        return '{"type":"open_web", "browser":"tgp", "use_ptlogin":"1", "url":"'..old_format_str..'"}';
    end;

    -- 内部使用的帮助函数，用于log增加本模块的filter
    inner_log = function (msg, core_msg)
        base_utility.log(string.format("[web_utility] %s", msg), core_msg);
    end;

    web_rsp_comm_data = function(table_param_input, retCode, msg)
        local rsp_data_tbl = {};
        rsp_data_tbl.retCode = retCode;
        rsp_data_tbl.msg = msg;
        if table_param_input ~= nil then 
            if table_param_input.src ~= nil then
                rsp_data_tbl.src = table_param_input.src;
            end
            if table_param_input.dest ~= nil then
                rsp_data_tbl.dest = table_param_input.dest;
            end;
            if table_param_input.seq_num ~= nil then
                rsp_data_tbl.seq_num = table_param_input.seq_num;
            end
            -- 助手web-js-sdk支持新增字段plugin_id+user_data+action
            if table_param_input.plugin_id ~= nil then
                rsp_data_tbl.plugin_id = table_param_input.plugin_id;
            end
            if table_param_input.user_data ~= nil then
                rsp_data_tbl.user_data = table_param_input.user_data;
            end
            if table_param_input.action ~= nil then
                rsp_data_tbl.action = table_param_input.action;
            end            
        end
        return rsp_data_tbl; 
    end;

    -- 返回事件的comm数据
    notify_event_comm_data = function(event_name, dest_id, msg, src_id)
        local event_data_table = {};
        event_data_table.retCode = 0;
        event_data_table.msg = "";
        if msg ~= nil then
             event_data_table.msg = msg;
        end
        if src_id ~= nil then
            event_data_table.src = src_id;
        else
            event_data_table.src = 0;
        end;
        event_data_table.dest = 0;
        if dest_id ~= nil then
            event_data_table.dest = tonumber(dest_id);
        end
        event_data_table.data = {};
        event_data_table.data.event = event_name;
        return event_data_table;
    end;

    -- 提供给js的获取client的基础信息
    handel_js_get_client_info = function (func_name, json, browser_id)
        if func_name ~= "m_get_client_info" then
            return
        end
        base_utility.log(string.format(
                "[web_utility][handel_js_get_client_info]json:%s", json));
        local param = base_utility.json_to_table(json);
        if nil ~= param then
            local rsp_table = web_utility.web_rsp_comm_data(param, 0, "");
            local netbar_flag = 0;
            local ver = 0;
            local dev_version = false;
            local str = NewStr(260);
            local language = "";
            local game_lib =
                base_utility.get_component_adapter("IGame_library",
                    "ierd_tgp.game_library.Get_game_library_adapter();");
            if nil ~= game_lib then
                dev_version = game_lib:get_tgp_version(str, 260, dev_version);
                netbar_flag = game_lib:get_bind_channel_id();
                ver = game_lib:get_tgp_version_num();
                local lang_cfg = ierd_tgp.game_library.LanguageConfig:new();
                game_lib:GetLanguageConfig(lang_cfg);
                language = lang_cfg.language;
                lang_cfg:delete();

                local tpfui =
                base_utility.get_component_adapter("ITpf_ui",
                    "ierd_tgp.tpf_ui.GetTPFUI();");

                local language_ver = tpfui:get_current_language();
                if language_ver == 0 then
                    language = "zh_CN";
                elseif language_ver == 1 then
                    language = "zh_HK";
                elseif language_ver == 2 then
                    language = "en_US";
                end

            end
            local bar_id = 0;
            local netbar_tool_id = 0;
            local web_st = "";
            local pkey_str = "";
            local proxy = "";
            local is_wow64 = false;
            local sys_name = "";
            local netbar_mgr =
                base_utility.get_component_adapter("INet_bar",
                    "ierd_tgp.net_bar.GetNetBarModule();");
            if netbar_mgr ~= nil then
                bar_id = netbar_mgr:get_bar_info().id;
                netbar_tool_id = netbar_mgr:get_netbar_tool_id();
            end
           
            local tgp_ticket = "";
            local login_mgr =
                 base_utility.get_component_adapter("ILogin_mgr",
                     "ierd_tgp.login_mgr.GetLoginMgr();");
            if login_mgr ~= nil then
                local info = ierd_tgp.login_mgr.WebStPod:new();
                login_mgr:GetWebSt(info);
                web_st = info.web_st;
                info:delete();
                local client_st_info = ierd_tgp.login_mgr.ClientStPod:new();
                login_mgr:GetClientSt(client_st_info);
                pkey_str = client_st_info.client_st;
                client_st_info:delete();
                local tgp_ticket_info = ierd_tgp.login_mgr.TGPTicketPod:new();
                login_mgr:GetTGPTicket(tgp_ticket_info);
                tgp_ticket = tgp_ticket_info.tgp_st;
                tgp_ticket_info:delete();
            end
            local tpf_ui =
                base_utility.get_component_adapter("ITpf_ui",
                    "ierd_tgp.tpf_ui.GetTPFUI();");
            local sys_param = ierd_tgp.tpf_ui.SysParams:new();
            tpf_ui:get_sys_params(sys_param);
            proxy = sys_param.proxy;
            is_wow64 = sys_param.is_wow64;
            sys_name = sys_param.sys_name;
            sys_param:delete();
            base_utility.log(string.format(
                "[web_utility][handel_js_get_client_info]net_bar_flag:%d", netbar_flag));
            local self_tgp_id = TLoginModule.GetTGPID();
            if self_tgp_id == nil or self_tgp_id == "" then
                self_tgp_id = TLoginModule.pLoginMgr:get_my_tgp_id();
            end

            local current_uin = TLoginModule.GetLoginUin();
            -- 获取登录类型和服务器环境参数
            local login_account_type = TLoginModule.GetLoginAccountType();
            local env_value = "";
            local env_tbl = comm_center.call_service("Srv_GetLoginEnvInfo", {});
            if env_tbl ~= nil and env_tbl.server_env ~= nil then
                env_value = env_tbl.server_env;
            end
            -- 获取业务票据
            local biz_ticket = "";
            local biz_tbl = comm_center.call_service("Service_GetRelatedTicket", {});
            if biz_tbl ~= nil and biz_tbl.biz_ticket ~= nil then
                biz_ticket = biz_tbl.biz_ticket;
            end
            -- 获取用户所在区 
            local user_region = "";
            local region_tbl = comm_center.call_service("Svr_GetUserSelfRegion", {});
            if region_tbl ~= nil and region_tbl.user_region ~= nil then
                user_region = region_tbl.user_region;
            end

            local is_overseas_ver_ = base_utility.is_type_of_oversea_ver();

            -- 如果是launcher，这里获得launcher对应的game_id，如果不是，则不设置该参数
            local  launch_game_id = 0;
            local launcher_params = base_utility.get_launcher_params();
            if launcher_params ~= nil and next(launcher_params) ~= nil and launcher_params.game_id then
                launch_game_id = tonumber(launcher_params.game_id);
            end;

            local client_type = base_utility.get_client_id();
             -- 获取是否是异常模式
            local svr_exception_mode = false;
            local tbl_data = comm_center.call_service("Srv_QueryExceptionMode", {});
            if tbl_data ~= nil and tbl_data.is_svr_exception_mode ~= nil then
                svr_exception_mode = tbl_data.is_svr_exception_mode;
            end
            -- 服务器异常模式清空数据
            if svr_exception_mode then
                self_tgp_id = 0;
                tgp_ticket = "";
                biz_ticket = "";
            end

            -- 颜色模式
            local color_mode = base_utility.get_color_mode();

            rsp_table.data = {uin = current_uin, dev_client = dev_version,
                is_netbar = netbar_flag, version = ver, language = language, pkey = pkey_str,
                bar_id = bar_id, netbar_tool_id = netbar_tool_id,
                web_st = web_st, proxy = proxy, is_wow64 = is_wow64,
                sys_name = sys_name, tgp_id = self_tgp_id, tgp_ticket = tgp_ticket, launch_game_id = launch_game_id,
                tgp_env = env_value, tgp_user_type = login_account_type, tgp_biz_ticket = biz_ticket, 
                is_overseas_ver = is_overseas_ver_, region = user_region, client_type = client_type,
                color_mode = color_mode};
            if param.callback_func ~= nil and param.callback_func ~= "" then
                local rsp_json = base_utility.table_to_json(rsp_table);
                web_utility.lua_call_js_by_id_ex(param.callback_func, rsp_json, browser_id);
            end
        end
    end;
    
    -- 提供给js调用的实时监控上报接口
    tgp_monitor_report = function(func_name, json, browser_id)
        if func_name ~= "tgp_monitor_report" then
            return;
        end;
        base_utility.log(string.format(
                "[web_utility][tgp_monitor_report]json: %s", json));
        local param = base_utility.json_to_table(json);
        if nil ~= param then
            local json_params = base_utility.table_to_json(param.data);
            local plugin_mgr =
                base_utility.get_component_adapter("IPlugin_mgr",
                    "ierd_tgp.tgp_plugin.GetPluginMgrModule();");
            if nil ~= plugin_mgr then
                plugin_mgr:TgpMonitorReport(json_params);
            end;
        end;
    end;

    -- 提供给js调用的精准广告信息上报接口
    tgp_accurate_ad_report = function (func_name, json, browser_id)
        if "tgp_accurate_ad_report" ~= func_name then
            return;
        end
        base_utility.log(string.format(
                "[web_utility][tgp_accurate_ad_report]json: %s", json));
        local param = base_utility.json_to_table(json);
        if nil ~= param and nil ~= param.data and nil ~= param.data.report_arr then
            local report_arr = param.data.report_arr;
            for i, v in ipairs(report_arr) do
                -- 构造上报信息
                local cur_object = v;
                local int_data_count = cur_object.int_arr_length;  -- int类型数据数
                local int_data_list = cur_object.int_arr;          -- int类型数据数组 下标从1开始
                local str_data_count = cur_object.str_arr_length;  -- str类型数据数
                local str_data_list = cur_object.str_arr;          -- str类型数据数组 下标从1开始

                base_utility.accurate_ad_report(int_data_list, int_data_count,
                    str_data_list, str_data_count);
            end
        end;
    end;

    open_llu = function()
        local tpfui = base_utility.get_component_adapter("ITpf_ui",
            "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:RemoveInterval("web_utility.open_llu");
        web_utility.lua_call_js_ex("tgp_updateGameLLU", 
            base_utility.table_to_json(web_utility.open_llu_param),
            CID_MAINFRAME_QBWEB);
    end;
    update_games = {};

    -- 任务中心窗口
    task_center_win = nil;

    -- 我的资产窗口
    my_assets_win = nil;

    open_link_convert_info = nil;

    open_llu_param = {};

    -- 个人中心子tab跳转地址
    profile_sub_tab_info = {
        HOME = {
            url = LoadStr("PROFILE_SUB_TAB_HOME");
        };
        VIP = {
            url = LoadStr("PROFILE_SUB_TAB_VIP");
        };
        GAME = {
            url = LoadStr("PROFILE_SUB_TAB_GAME");
        };
        SCREENSHOT = {
            url = LoadStr("PROFILE_SUB_TAB_SCREENSHOT");
        };
        VIDEO = {
            url = LoadStr("PROFILE_SUB_TAB_VIDEO");
        };
        POST = {
            url = LoadStr("PROFILE_SUB_TAB_POST");
        };
        COMMENT = {
            url = LoadStr("PROFILE_SUB_TAB_COMMENT");
        };
        BACKPACK = {
            url = LoadStr("PROFILE_SUB_TAB_BACKPACK");
        };
    };
};
web_utility.init();
